package com.pai4j.pgc.controller.community;
import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.common.config.annotation.ValidateLogin;
import com.pai4j.common.helper.SessionHelper;
import com.pai4j.domain.community.vo.request.CCAnswerSaveRequestVO;
import com.pai4j.domain.community.vo.response.cc.CTCAnswerListVO;
import com.pai4j.pgc.service.community.CCAnswerService;
import com.pai4j.remote.pgc.community.CCAnswerClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 技术社区问答专栏
 *
 * @author: CYM-pai
 * @date: 2025/10/26 20:42
 **/
@RestController
public class CCAnswerController implements CCAnswerClient {

    @Autowired
    private CCAnswerService answerService;

    @Override
    @ValidateLogin
    public PAIResponseBean<Long> save(@RequestBody CCAnswerSaveRequestVO answerSaveRequestVO) {
        answerSaveRequestVO.validate();
        String userId = SessionHelper.getCurrentUserId();
        return PAIResponseBeanUtil.success(answerService.save(answerSaveRequestVO, userId));
    }

    /**
     * 问题最新回复列表查询
     * @param questionId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public PAIPageResponseBeanUtil<CTCAnswerListVO> newPageList(@PathVariable Long questionId,
                                                                @PathVariable Integer pageNo,
                                                                @PathVariable Integer pageSize) {
        String userId = SessionHelper.getCurrentUserId();
        PAIPageResponseBeanUtil<CTCAnswerListVO> page = answerService.newPageList(questionId, userId, pageNo, pageSize);
        return page;
    }
}
